<?php

namespace app\common\validate;

use think\Validate;

class StCard extends Validate
{
    //protected $batchValidate = true;
    //定义验证规则
    protected $rule = [
        'uid|持卡人'   => 'require|unique:st_card',
        'card_type'   => 'require',
        'valid_start_time'=> 'require',
        'valid_end_time'  => 'require',
    ];

    //定义验证提示
    protected $message = [
        'card_type.require'  => '卡类型不能为空',
        'uid.require'        => '持卡人不能为空',
        'valid_start_time.require'=> '有效时间不能为空',
        'valid_end_time.require'  => '有效时间不能为空',
    ];

    protected $scene = [
        'uid'  =>  ['uid'],
    ];

    // 编辑 验证场景定义
    public function sceneEdit()
    {
        return $this->only(['card_type','valid_start_time','valid_end_time'])
            ->remove('uid', 'require|unique');
    }

    // 批量充值 验证场景定义
    public function sceneRecharge()
    {
        return $this->only(['card_type','valid_start_time','valid_end_time'])
            ->append('id', 'require')
            ->remove('uid', 'between');
    }
}